home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / archiver / mdcd10.zip / MDCD1213.ASM < prev    next >
Assembly Source File  |  1988-10-26  |  61KB  |  1,221 lines

  1. ;---- 10/26/1988  00:26:45 ----}
  2.           name      mdcd1213
  3.           page      82,132
  4.           title     'MDCD1213.OBJ 12/13 bit LZW file compress/decompress
  5. ;-----------------------------------------------------------------------------
  6. ;                                                                            -
  7. ;                                   `MDCD1213'                               -
  8. ;                                                                            -
  9. ; This is a modified version of LZ.ARC, obtained from the EXEC PC BBS        -
  10. ; in Milwaukee WI. on 8/20/88.  It has been changed to work as an external   -
  11. ; modlule and has been tested with Turbo Pascal 5.0.                         -
  12. ;                                                                            -
  13. ; It was assembled with Turbo Assembler 1.0 but will assemble with MASM.     -
  14. ; but will assemble with MASM.  The following modifications have been made:  -
  15. ;                                                                            -
  16. ;   1. Removed the malloc memory allocation for the hash table out to        -
  17. ;       the caller so that it can be allocated from the heap.                -
  18. ;   2. Added the CompressFile & DecompressFile function interface.           -
  19. ;   3. Minor cleanup and use of equ values for easy buffer size changes.     -
  20. ;   4. Initialized DS variables normally done by MASM/LINK, but not by some  -
  21. ;       other HLL's (e.g. Turbo Pascal).                                     -
  22. ;   5. Input file & output file allocated and opened externally by caller.   -
  23. ;       Only the file handles are passed to this module.                     -
  24. ;   6. Super fast CRC 16 (communications type) routine added to accumulate   -
  25. ;       the compressed & decompressed file's CRC for reliability.            -
  26. ;   7. Original program used a macro file.  The few that were used were      -
  27. ;       removed and coded inline for single module simplicity.               -
  28. ;   8. Increased disk input and output buffers to 8192 bytes each            -
  29. ;       (from 1024). This seems to be a good trade-off for speed/memory.     -
  30. ;   9. Moved the disk input and output buffers to CS to preserve precious    -
  31. ;       Turbo Pascal DS space.                                               -
  32. ;  10. Combined LZCOMP.ASM & LZDCMP.ASM into 1 module                        -
  33. ;  11. Allowed the beginning file offset to write to and read from to be     -
  34. ;       specified to provide for (n) files in a compressed file.             -
  35. ;  12. Replaced DIVide instructions with shifts, ands and moves.             -
  36. ;  13. Added 13 bit LZW compression based on passed parameter.               -
  37. ;                                                                            -
  38. ;                       Modified by..                                        -
  39. ;                         Mike Davenport                                     -
  40. ;                         Mike Davenport & Associates                        -
  41. ;                         6751 N. Blackstone Ave. Suite 252                  -
  42. ;                         Fresno CA  93710                                   -
  43. ;                         Voice: (209) 298-8846                              -
  44. ;                         CIS:   76676,1362                                  -
  45. ;                         PLINK: MIKE D                                      -
  46. ;                         GENIE: MDAVENPORT                                  -
  47. ;                         Amiga Techniques + PC Tech BBS - (GT POWER)        -
  48. ;                         (209) 298-8453 - 1200-9600 HST (24 hours)          -
  49. ;                                                                            -
  50. ;                       Original Author..                                    -
  51. ;                         Tom Pfau                                           -
  52. ;                         Digital Equipment Corporation                      -
  53. ;                         Parsippany, NJ                                     -
  54. ;                                                                            -
  55. ;-----------------------------------------------------------------------------
  56. ;                                                                            -
  57. ;                          ---------------------                             -
  58. ;                          MODULE CHANGE HISTORY                             -
  59. ;                          ---------------------                             -
  60. ;                                                                            -
  61. ; change#  ..date..  by  .................. change ........................  -
  62. ;                                                                            -
  63. ;   000    09-06-88  md  Original module creation                            -
  64. ;   001    10-19-88  md  added 13 bit LZW compression                        -
  65. ;   001    10-26-88  md  Original module finished                            -
  66. ;                                                                            -
  67. ;-----------------------------------------------------------------------------
  68.  
  69.  
  70. ;----------
  71. ; constants
  72. ;----------
  73. clear            equ     256            ;Clear code
  74. eof              equ     257            ;End of file marker
  75. fhdr_len         equ     128            ;size of file header for file type 1
  76. first_free       equ     258            ;First free code
  77.  
  78.  
  79. ;NOTE: this module will not handle buffers larger than 8k due to the design
  80. ;      of the original code.  It carries the total bits in the buffer waiting
  81. ;      to be written to disk in a word then divides by 8 to compare bytes.
  82. ;      Buffers > 8192 will cause the WORD that holds the total bits to
  83. ;      overflow.  I decided not to mess with this because buffers > 4096
  84. ;      didn't seem to have a worthwhile memory vs. speed tradeoff that
  85. ;      justified the non-trivial changes.   In other words, I'm lazy!
  86.  
  87. input_data_size  equ     8192           ;input data buffer size
  88. input_data_chk   equ     8187           ;size to check end of input coming up
  89. output_data_size equ     8192           ;output data buffer size
  90. output_data_chk  equ     8188           ;size to check output buffer write
  91.  
  92.  
  93. ;--------------------------
  94. ; compress hash table entry
  95. ;--------------------------
  96. hash_rec        struc
  97. first   dw      ?                       ; First entry with this value
  98. next    dw      ?                       ; Next entry along chain
  99. char    db      ?                       ; Suffix char
  100. hash_rec        ends
  101.  
  102. ;----------------------------
  103. ; decompress hash table entry
  104. ;----------------------------
  105. dhash_rec       struc
  106. dnext   dw      ?                       ; prefix code
  107. dchar   db      ?                       ; suffix char
  108. dhash_rec       ends
  109.  
  110. ;------------------------------ DATA SEGMENT ---------------------------------
  111.  
  112. data    segment word
  113.  
  114. ; data will be initialized upon entry into CompressFile or DecompressFile
  115. ; because some HLL's do not do this as does MASM/LINK.
  116.  
  117.  
  118. ; original LZCOMP.ASM data
  119.  
  120. bit_offset      dw      ?               ;
  121. free_code       dw      ?               ;
  122. hash_seg        dw      ?               ;segment of hash table from caller
  123. input_handle    dw      ?               ;input file handle from caller
  124. input_offset    dw      0               ;offset of next byte to read for input
  125. input_size      dw      0               ;number of input bytes read
  126. k               db      ?               ;
  127. max_code        dw      ?               ;
  128. nbits           dw      ?               ;number of bits for current code size
  129. output_handle   dw      ?               ;output file handle from caller
  130. prefix_code     dw      ?               ;
  131.  
  132. ; original data unique to LZDCMP.ASM
  133.  
  134. dhash_seg       dw      ?
  135. cur_code        dw      ?
  136. old_code        dw      ?
  137. in_code         dw      ?
  138. stack_count     dw      0
  139. dmax_code       dw      512             ;hash table bytes for 9 bit codes
  140. fin_char        db      ?
  141. masks           dw      1ffh,3ffh,7ffh,0fffh,0ffffh  ;9-13 bit masks
  142. dbit_offset